<script type="text/javascript">
function checknode(obj) {
    var chk = $("input[type='checkbox']");
    var count = chk.length;
    var num = chk.index(obj);
    var level_top = level_bottom =  chk.eq(num).attr('level');

    for (var i=num; i>=0; i--) {
        var le = chk.eq(i).attr('level');
        if(eval(le) < eval(level_top)) {
            chk.eq(i).attr("checked",true);
            var level_top = level_top-1;
        }
    }

    for (var j=num+1; j<count; j++){
        var le = chk.eq(j).attr('level');
        if(chk.eq(num).attr("checked")=='checked') {

            if(eval(le) > eval(level_bottom)) chk.eq(j).attr("checked",true);
            else if(eval(le) == eval(level_bottom)) break;
        }
        else {
            if(eval(le) > eval(level_bottom)) chk.eq(j).attr("checked",false);
            else if(eval(le) == eval(level_bottom)) break;
        }
    }
}
</script>
<style>.mainnav_title{display:none;}span.w1{float:left;width:89px}</style>

<form id="myform" name="myform" action="{:U('Access/insert')}" method="post">
    <input type="hidden" id="rid" name="rid" value="{$rid}" />
    <table class="table" id="dnd-example">
        <tbody>
            <volist name="node" id="r" >

            <tr>
                <td colspan="2" bgcolor="#F0F5FB" align="center" height="40"><b>{$r[groupinfo][name]}</b></td>
            </tr>
                <volist name="r[data]" id="rr">

                <if condition="$rr[level]==1">
                <tr>
                    <td style='padding-left:15px;' bgcolor="#F8FAFC"><input type='checkbox' name='nid[{$rr.id}]' value='{$rr.id}'  level='{$rr.level}' {$rr.selected}  onclick='javascript:checknode(this);' />&nbsp;{$rr.title}
                    </td>

                    <td>
                        <volist name="node[$rr[groupid]][data]" id="rrr" >
                            <if condition="$rrr[pid]==$rr[id]">
                            <span class="w1">
                            <input type='checkbox' name='nid[{$rrr.id}]' value='{$rrr.id}'  level='{$rrr.level}' {$rrr.selected}  onclick='javascript:checknode(this);' /> {$rrr.title} &nbsp;</span>
                            </if>
                        </volist>
                    </td>

                </tr>

                </if>
                </volist>
            </volist>
        </tbody>
    </table>
    <div class="panel-footer">
        <input type='checkbox' name='nid[1]' value='1' level='0' {if array_key_exists(1,$alist)}checked{/if}  onclick='javascript:checknode(this);' />
        <input type="hidden" name="isajax" value="1" />
        <input name="dosubmit" type="submit" value="确认" class="btn btn-primary btn-sm">
    </div>
</form>
